﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TKB.Services.BusinessObjects;

public partial class Login : TKBBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            
        }
    }
    
    protected void LinkButtonGiris_Click(object sender, EventArgs e)
    {
        CheckInputs();
    }
    
    private void CheckInputs()
    {
        if (TextBoxKullaniciAdi.Text == String.Empty)
        {
            LabelHataMesaji.Text = "Kullanıcı Adı Giriniz!";
            return;
        }
        else if (TextBoxParola.Text == String.Empty)
        {
            LabelHataMesaji.Text = "Şifre Giriniz!";
            return;
        }
        else
            IsUserAuthenticate();
    }

    private void IsUserAuthenticate()
    {
        string pUserName = TextBoxKullaniciAdi.Text;
        string pPassword = TextBoxParola.Text;
        string pName = String.Empty, pSurname = String.Empty;
        Guid pUserID = Guid.Empty;

        UserBS user = new UserBS();
        user.IsUserValid(out pUserID, pUserName, pPassword, out pName, out pSurname);
        if (pUserID == Guid.Empty)
            LabelHataMesaji.Text = "Hatalı Giriş!";
        else
        {
            SessionHelper.UserID = pUserID;
            SessionHelper.UserName = pName;
            SessionHelper.UserSurName = pSurname;
            Response.Redirect("~/Ithalat/MuayeneListesi.aspx");
        }
    }
}
